from appium import webdriver
import os,time
from time import sleep
#
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as  EC
class Base():
    def __init__(self):
        os.system('adb root')
        cap={
            "platformName": "Android",
            "appium:deviceName": "emulator-5554",
            "appium:noReset": True,
            "appium:appPackage": "com.kongfz.app",
            "appium:appActivity": "com.kongfz.app.home.mvvm.homepage.HomeActivity"
        }
        self.drive=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.drive.implicitly_wait(15)
        sleep(5)
    def find_ele(self,loc):
        if type(loc)==str:
            return self.drive.find_element_by_android_uiautomator(loc)
        else:
            return self.drive.find_element(*loc)
    def find_wait_ele(self,loc):
        return WebDriverWait(self.drive,15).until(EC.presence_of_element_located((loc)))
    def get_key_value(self,loc,key):
        self.find_ele(loc)
        return self.drive.find_element(key)
    def jieping(self):
        t = time.struct_time("%Y%m%d%H%M%S",time.localtime())
        self.drive.save_screenshot(t)
    def qingqiao(self,x,y):
        self.drive.tap([(x,y)],500)
    def huadong(self,x1,y1,x2,y2):
        self.drive.swipe(x1,y1,x2,y2)
    def tuichu(self):
        self.drive.quit()
